import Loading from '../../components/Loading/Loading.vue'
import Rotation from '../../components/Rotation/Rotation.vue'
import HongBao from '../../components/RedPacket/RedPacket.vue'
import couponVue from '../../components/pupUp/youhuiquan.vue'
export default {
	components: {
		Loading,
		Rotation,
		HongBao,
		couponVue
	},
	props: [
		'courseID'
	],
	data() {
		return {
			CustomBar: this.CustomBar,
			isCategory: false,
			categoryList: [],
			msg: "测试成功",
			isLoading: false,
			loadStatus: 'load',
			bodtyH: this.bodtyH - this.CustomBar,
			domain: this.Reques.DomainH,
			lunBoData: [], //轮播数据
			isCard: false,
			footH: this.CustomBar,
			TabCur: 0,
			scrollLeft: 0,
			scrollP: 20, //滚动条的位置
			scrollp1: 0,
			scrollData: {
				isload: 'over',
				isButtom: false, //是否滚到底部
				page: 0,
			},
			categoryIndex:0,
			courseList: [], //课程列表
			category_type: 14,
		}
	},
	onReady() {
		/**
		 * 加载目录
		 */

		this.Reques.commonQuest('index/api/category.html', "POST", {}).then((res) => {

			if (res.statusCode == 200 && res.data.code == 0) {
				this.categoryList = res.data.data[0].category;
			}

		}, (err) => {
			console.log(err);
			this.loadStatus = 'error2';
		});
		this.loadData();


	},
	methods: {
		/**
		 * 滚动到底部进行加载
		 */
		gundongButton() {
			this.scrollData.isload = 'loading'; //加载初始化到最初状态
			(this.scrollData.isButtom == false) ? this.loadData(): "";

			this.scrollData.isButtom = true; //改变底部的状态，滚动到底部开启加载数据的状态
			console.log(this.lunBoData);
		},
		/**
		 * 选择菜单
		 */
		click_category(type, name,index) {
			this.categoryIndex=index;
			this.hideModal();
			this.isLoading = false;
			this.loadStatus = 'load';
			this.category_type = type;
			this.$emit("changeTitle", name);
			this.scrollData.page = 0;
			this.courseList = [];
			this.loadData();


		},

		/**隐藏菜单
		 * @param {Object} e
		 */
		hideModal(e) {
			this.isCategory = false;
		},
		/**
		 * 加载数据
		 * 请求成功一次数据关闭底部状态
		 * 
		 */
		loadData() {
			console.log("加载数据");

			let dat = {
				page: this.scrollData.page,
				type: this.category_type
			}
			this.Reques.commonQuest('index/api/home.html', "POST", dat).then((res) => {
				if (res.statusCode == 200 && res.data.code == 0) {
					(res.data.data[0].lunbo != "") ? (this.lunBoData = res.data.data[0].lunbo) : this.lunBoData=[];
					this.isLoading = true;
					(res.data.data[0].list != "") ? (this.scrollData.page++) : "";
					 this.$nextTick(()=>{
						 for (let i in res.data.data[0].list) {	
						 	res.data.data[0].list[i].thumb=this.Reques.DomainH+res.data.data[0].list[i].thumb;	
						 	this.courseList.push(res.data.data[0].list[i]);
						 }
						 console.log(this.courseList);
					 });
					 
			             
					this.scrollData.isButtom = false; //滚动状态进行初始化
					setTimeout(() => {
						this.scrollData.isload = 'over'; //加载初始化到最初状态
					}, 1000);

				} else {
					this.loadStatus = 'error2';
				}

			}, (err) => {
				console.log(err);
				this.loadStatus = 'error2';
			});
		},
		/**
		 * 打开筛选菜单
		 */
		changeCategory() {
			(this.isCategory == false) ? this.isCategory = true: this.isCategory = false;
		},
		/**
		 * 滚动的监听
		 * @param {Object} e
		 */
		gundong(e) {

			this.scrollp1 = e.detail.scrollTop;

		},

		todate(str) {
			return this.Reques.to_date(str, 0);
		},
		/**
		 * 发放优惠券
		 * @param {Object} dat
		 */
		sendOutCoupon(dat) {
			this.Reques.checkLogin((d) => {
				if (!d) {
					uni.getStorage({
						key: "startTime",
						success: (res) => {
							console.log("starttIEM" + res)
						},
						fail: () => {
							this.$refs.RedPack.openRed();
							uni.setStorage({
								key: "startTime",
								success: () => {

									console.log("存储成功")
								},
								fail: () => {
									console.log("存储失败");
								}
							})
						}
					});


				}

			});


		},




		/**
		 * 进入课程详情
		 * @param {Object} id
		 */
		toGoods(id) { //跳转商品详情
			console.log("课程的id" + id);
			uni.navigateTo({
				animationDuration: 500,
				url: "/pages/detail/index?id=" + id,
				animationType: 'slide-in-bottom',

			});
		}



	}





}
